home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Examples / Table / Sources / TblSel.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  11.6 KB  |  389 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                TblSel.cpp
  4. //    Release Version:    $ 1.0d11 $ 
  5. //
  6. //    Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "Table.hpp"
  11.  
  12. // ----- TablePart Includes -----
  13.  
  14. #ifndef TBLSEL_H
  15. #include "TblSel.h"
  16. #endif
  17.  
  18. #ifndef TBLPART_H
  19. #include "TblPart.h"
  20. #endif
  21.  
  22. #ifndef TBLPROXY_H
  23. #include "TblProxy.h"
  24. #endif
  25.  
  26. #ifndef TBLFRAME_H
  27. #include "TblFrame.h"
  28. #endif
  29.  
  30. #ifndef TBLLINK_H
  31. #include "TblLink.h"
  32. #endif
  33.  
  34. // ----- ODF Includes -----
  35.  
  36. #ifndef FWFRAME_H
  37. #include "FWFrame.h"
  38. #endif
  39.  
  40. #ifndef FWRECT_H
  41. #include "FWRect.h"
  42. #endif
  43.  
  44. #ifndef FWUTIL_H
  45. #include "FWUtil.h"
  46. #endif
  47.  
  48. #ifndef FWPRESEN_H
  49. #include "FWPresen.h"
  50. #endif
  51.  
  52. // ----- OS Layer -----
  53.  
  54. #ifndef FWODGEOM_H
  55. #include "FWODGeom.h"
  56. #endif
  57.  
  58. #ifndef FWEVENT_H
  59. #include "FWEvent.h"
  60. #endif
  61.  
  62. // ----- OpenDoc Includes -----
  63.  
  64. #ifndef SOM_ODShape_xh
  65. #include <Shape.xh>
  66. #endif
  67.  
  68. #ifndef SOM_ODTransform_xh
  69. #include <Trnsform.xh>
  70. #endif
  71.  
  72. #ifndef SOM_ODSession_xh
  73. #include <ODSessn.xh>
  74. #endif
  75.  
  76. //========================================================================================
  77. // RunTime Info
  78. //========================================================================================
  79.  
  80. #ifdef FW_BUILD_MAC
  81. #pragma segment odfTable
  82. #endif
  83.  
  84. //========================================================================================
  85. //    class CTableSelection
  86. //========================================================================================
  87.  
  88. //----------------------------------------------------------------------------------------
  89. //    CTableSelection::CTableSelection
  90. //----------------------------------------------------------------------------------------
  91.  
  92. CTableSelection::CTableSelection(Environment* ev, CTablePart* tablePart) :
  93.     FW_CEmbeddingSelection(ev, TRUE, TRUE),    // allow publish and subscribe
  94.     fTablePart(tablePart),
  95.     fCell(0,0)
  96. {
  97. }
  98.  
  99. //----------------------------------------------------------------------------------------
  100. //    CTableSelection::~CTableSelection
  101. //----------------------------------------------------------------------------------------
  102.  
  103. CTableSelection::~CTableSelection()
  104. {
  105. }
  106.  
  107. //----------------------------------------------------------------------------------------
  108. //    CTableSelection::IsEmpty
  109. //----------------------------------------------------------------------------------------
  110.  
  111. FW_Boolean CTableSelection::IsEmpty(Environment* ev) const
  112. {
  113.     return (fTablePart->CellToProxy(ev, fCell) == NULL);
  114. }
  115.  
  116. //----------------------------------------------------------------------------------------
  117. //    CTableSelection::IsSelectionOnlyOneProxy
  118. //----------------------------------------------------------------------------------------
  119.  
  120. FW_MProxy* CTableSelection::IsSelectionOnlyOneProxy(Environment* ev) const
  121. {
  122.     return fTablePart->CellToProxy(ev, fCell);
  123. }
  124.  
  125. //----------------------------------------------------------------------------------------
  126. //    CTableSelection::CloseSelection
  127. //----------------------------------------------------------------------------------------
  128.  
  129. void CTableSelection::CloseSelection(Environment* ev)
  130. {
  131.     InvalidateSelection(ev);
  132. }
  133.  
  134. //----------------------------------------------------------------------------------------
  135. //    CTableSelection::ClearSelection
  136. //----------------------------------------------------------------------------------------
  137.  
  138. FW_Boolean CTableSelection::ClearSelection(Environment* ev)
  139. {
  140.     CTableProxy* proxy = fTablePart->CellToProxy(ev, fCell);
  141.     if (proxy)
  142.     {
  143.         fTablePart->AboutToClearCell(ev, fCell);    // break existing links before removing the proxy
  144.  
  145.         FW_CPresentationFrameIterator piter(GetPresentation(ev));
  146.         FW_CFrame* frame = piter.First();
  147.         fTablePart->ContentUpdated(ev, frame, kODUnknownUpdate);
  148.  
  149.         //--- Remove the proxy ---
  150.         proxy->DetachEmbeddedFrames(ev);
  151.         fTablePart->RemoveProxy(proxy);
  152.         InvalidateSelection(ev);
  153.         return TRUE;
  154.     }
  155.     return FALSE;
  156. }
  157.  
  158. //----------------------------------------------------------------------------------------
  159. //    CTableSelection::SelectAll
  160. //----------------------------------------------------------------------------------------
  161.  
  162. void CTableSelection::SelectAll(Environment* ev)
  163. {
  164. }
  165.  
  166. //----------------------------------------------------------------------------------------
  167. //    CTableSelection::InvalidateSelectBorder
  168. //----------------------------------------------------------------------------------------
  169.  
  170. void CTableSelection::InvalidateSelectBorder(Environment* ev, const CCell& cell)
  171. {
  172.     FW_CRect rect;
  173.     fTablePart->FindRect(cell, rect);
  174.     rect.Inset(FW_IntToFixed(-1), FW_IntToFixed(-1));
  175.     
  176.     FW_CAcquiredODShape aqShape1 = ::FW_NewODShape(ev, rect);
  177.     
  178.     rect.Inset(FW_IntToFixed(2), FW_IntToFixed(2));
  179.     
  180.     {    
  181.         FW_CAcquiredODShape aqShape2 = ::FW_NewODShape(ev, rect);
  182.     
  183.         aqShape1->Subtract(ev, aqShape2);
  184.     }
  185.     
  186.     GetPresentation(ev)->Invalidate(ev, aqShape1);
  187. }
  188.  
  189. //----------------------------------------------------------------------------------------
  190. //    CTableSelection::Select
  191. //----------------------------------------------------------------------------------------
  192.  
  193. void CTableSelection::Select(Environment* ev, const CCell& cell, FW_Boolean drawNow)
  194. {
  195.     if (drawNow)
  196.     {
  197.         // ----- Change the selection feedback for the active frame only -----
  198.         FW_CPresentationFrameIterator ite1(GetPresentation(ev));
  199.         for (CTableFrame* frame = (CTableFrame*)ite1.First(); ite1.IsNotComplete(); frame = (CTableFrame*)ite1.Next())
  200.             if (frame->IsActive(ev))
  201.             {
  202.                 FW_CFrameFacetIterator ite(ev, frame);
  203.                 for (ODFacet* facet = ite.First(ev); ite.IsNotComplete(ev); facet = ite.Next(ev))
  204.                 {
  205.                     FW_CFacetContext fc(ev, facet);
  206.                     
  207.                     frame->DrawSelectBorder(ev, fc, fCell);
  208.                     frame->DrawSelectBorder(ev, fc, cell);
  209.                 }
  210.             }
  211.     }
  212.     else
  213.     {
  214.         InvalidateSelectBorder(ev, fCell);
  215.         InvalidateSelectBorder(ev, cell);
  216.     }
  217.     
  218.     CTableProxy* proxy = fTablePart->CellToProxy(ev, fCell);
  219.         
  220.     fCell = cell;
  221.  
  222.     proxy = fTablePart->CellToProxy(ev, fCell);
  223. }
  224.  
  225. //----------------------------------------------------------------------------------------
  226. //    CTableSelection::CreateSelectionFrameShape
  227. //----------------------------------------------------------------------------------------
  228.  
  229. ODShape* CTableSelection::CreateSelectionFrameShape(Environment* ev)
  230. {
  231.     FW_CRect rect;
  232.     fTablePart->FindRect(fCell, rect);
  233.  
  234.     ODShape* shape = ::FW_NewODShape(ev, rect);
  235.     return shape;
  236. }
  237.  
  238. //----------------------------------------------------------------------------------------
  239. //    CTableSelection::CreateSelectionShape
  240. //----------------------------------------------------------------------------------------
  241.  
  242. ODShape* CTableSelection::CreateSelectionShape(Environment* ev, ODFacet* facet, FW_CFrame* frame) const
  243. {
  244.     return ((CTableSelection*)this)->CreateSelectionFrameShape(ev);
  245. }
  246.  
  247. //----------------------------------------------------------------------------------------
  248. //    CTableSelection::DoExternalizeSelection
  249. //----------------------------------------------------------------------------------------
  250.  
  251. void CTableSelection::DoExternalizeSelection(Environment* ev, 
  252.                                             ODStorageUnit* destinationSU,
  253.                                             FW_CCloneInfo* cloneInfo)
  254. {
  255.     FW_UNUSED(ev);
  256.     FW_UNUSED(destinationSU);
  257.     FW_UNUSED(cloneInfo);
  258. }
  259.  
  260. //----------------------------------------------------------------------------------------
  261. //    CTableSelection::DoInternalizeSelection
  262. //----------------------------------------------------------------------------------------
  263.  
  264. FW_Boolean CTableSelection::DoInternalizeSelection(Environment* ev, 
  265.                                                    ODStorageUnit* sourceSU,
  266.                                                    FW_CCloneInfo* cloneInfo)
  267. {
  268.     FW_UNUSED(ev);
  269.     FW_UNUSED(sourceSU);
  270.     FW_UNUSED(cloneInfo);
  271.     
  272.     return FALSE;
  273. }
  274.  
  275. //----------------------------------------------------------------------------------------
  276. //    CTableSelection::InvalidateSelection
  277. //----------------------------------------------------------------------------------------
  278.  
  279. void CTableSelection::InvalidateSelection(Environment* ev)
  280. {
  281.     FW_CAcquiredODShape aqShape(this->CreateSelectionFrameShape(ev));
  282.     GetPresentation(ev)->Invalidate(ev, aqShape);
  283. }
  284.  
  285. //----------------------------------------------------------------------------------------
  286. // CTableSelection::SelectProxy
  287. //----------------------------------------------------------------------------------------
  288.  
  289. void CTableSelection::SelectProxy(Environment* ev, CTableProxy* proxy)
  290. {
  291.     CCell cell = proxy->GetCell();
  292.     this->Select(ev, cell, TRUE);    // drawNow?
  293. }
  294.  
  295. //----------------------------------------------------------------------------------------
  296. //    CTableSelection::IsMouseInDraggableItem
  297. //----------------------------------------------------------------------------------------
  298.  
  299. FW_Boolean CTableSelection::IsMouseInDraggableItem(Environment* ev, FW_CFrame* frame, const FW_CMouseEvent& theMouseEvent, FW_Boolean inBackground) const
  300. {
  301.     FW_CPoint where = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
  302.  
  303.     CCell cell;
  304.     ETableLoc tl = fTablePart->HitTest(ev, (CTableFrame*)frame, where, cell);
  305.     
  306.     return (tl == kTLCell && fTablePart->CellToProxy(ev, cell) != NULL);
  307. }
  308.  
  309. //----------------------------------------------------------------------------------------
  310. // CTableSelection::UpdateSelectionOnMouseDown
  311. //----------------------------------------------------------------------------------------
  312.  
  313. void CTableSelection::UpdateSelectionOnMouseDown(Environment* ev, 
  314.                                             const FW_CMouseEvent& mouseEvent,
  315.                                             ODFacet* embeddedFacet,
  316.                                             FW_Boolean inEmbeddedFrameBorder,
  317.                                             FW_Boolean inBackground)
  318. {
  319.     CTableFrame* tableFrame = (CTableFrame*)FW_CFrame::ODtoFWFrame(ev, mouseEvent.GetFacet(ev)->GetFrame(ev));
  320.     
  321.     if (tableFrame->IsGridShown(ev))
  322.     {
  323.         FW_Boolean select = FALSE;
  324.         CCell cell;
  325.         
  326.         if (inEmbeddedFrameBorder)
  327.         {
  328.             FW_MProxy* proxy = tableFrame->GetProxy(ev, embeddedFacet->GetFrame(ev));
  329.             FW_ASSERT(proxy);
  330.             
  331.             cell = ((CTableProxy*)proxy)->GetCell();    
  332.             select = TRUE;
  333.         }
  334.         else
  335.         {
  336.             FW_CPoint where = mouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
  337.     
  338.             ETableLoc tl = fTablePart->HitTest(ev, tableFrame, where, cell);
  339.         
  340.             select = (tl == kTLCell && cell != GetCell());
  341.         }
  342.         
  343.         if (select)
  344.             Select(ev, cell, TRUE);
  345.     }
  346. }
  347.  
  348. //----------------------------------------------------------------------------------------
  349. //    CTableSelection::CanSubscribe
  350. //---------------------------------------------------------------------------------------
  351. FW_Boolean CTableSelection::CanSubscribe(Environment* ev, ODPasteAsMergeSetting& setting)
  352. {
  353.     setting = kODPasteAsEmbedOnly;    // table has no content to merge
  354.  
  355.     // Check whether the selected cell already contains an embedded part.
  356.     // If it doesn't, allow Paste As.
  357.     /* MEB-- what about Drag&Drop? */
  358.     return this->IsEmpty(ev);
  359. }
  360.  
  361. //----------------------------------------------------------------------------------------
  362. //    CTableSelection::IsSelectionPublishable
  363. //----------------------------------------------------------------------------------------
  364.  
  365. FW_Boolean CTableSelection::IsSelectionPublishable(Environment* ev)
  366. {
  367.     FW_Boolean result = fAllowPublish;
  368.  
  369.     if (fAllowPublish)
  370.     {
  371.         // make sure the cell is not a link destination
  372.         CTableLinkManager* linkMgr = (CTableLinkManager*)fTablePart->GetLinkManager(ev);
  373.         if (linkMgr->CellToSubscribeLink(ev, this->GetCell()))
  374.             result = FALSE;
  375.     }
  376.  
  377.     return result;
  378. }
  379.  
  380. //----------------------------------------------------------------------------------------
  381. //    CTableSelection::DoFindPublisher
  382. //----------------------------------------------------------------------------------------
  383. FW_CPublishLink* CTableSelection::DoFindPublisher(Environment* ev)    // Override
  384. {
  385.     CTableLinkManager* linkMgr = (CTableLinkManager*)fTablePart->GetLinkManager(ev);
  386.     return linkMgr->CellToPublishLink(ev, fCell);
  387. }
  388.  
  389.